﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class TimingCategory
    {
        private readonly Chain.IDAL.TimingCategory dal = new Chain.IDAL.TimingCategory();

        public int Add(Chain.Model.TimingCategory model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.TimingCategory> DataTableToList(DataTable dt)
        {
            List<Chain.Model.TimingCategory> list = new List<Chain.Model.TimingCategory>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.TimingCategory item = new Chain.Model.TimingCategory();
                    if ((dt.Rows[i]["CategoryID"] != null) && (dt.Rows[i]["CategoryID"].ToString() != ""))
                    {
                        item.CategoryID = int.Parse(dt.Rows[i]["CategoryID"].ToString());
                    }
                    if ((dt.Rows[i]["CategoryName"] != null) && (dt.Rows[i]["CategoryName"].ToString() != ""))
                    {
                        item.CategoryName = dt.Rows[i]["CategoryName"].ToString();
                    }
                    if ((dt.Rows[i]["CategoryFatherID"] != null) && (dt.Rows[i]["CategoryFatherID"].ToString() != ""))
                    {
                        item.CategoryFatherID = int.Parse(dt.Rows[i]["CategoryFatherID"].ToString());
                    }
                    if ((dt.Rows[i]["CategoryShopID"] != null) && (dt.Rows[i]["CategoryShopID"].ToString() != ""))
                    {
                        item.CategoryShopID = int.Parse(dt.Rows[i]["CategoryShopID"].ToString());
                    }
                    if ((dt.Rows[i]["CategoryUserID"] != null) && (dt.Rows[i]["CategoryUserID"].ToString() != ""))
                    {
                        item.CategoryUserID = int.Parse(dt.Rows[i]["CategoryUserID"].ToString());
                    }
                    if ((dt.Rows[i]["CategoryrRemark"] != null) && (dt.Rows[i]["CategoryrRemark"].ToString() != ""))
                    {
                        item.CategoryrRemark = dt.Rows[i]["CategoryrRemark"].ToString();
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int CategoryID)
        {
            Chain.BLL.TimingProject project = new Chain.BLL.TimingProject();
            return (!project.ExistsCategory(CategoryID) && this.dal.Delete(CategoryID));
        }

        public bool DeleteList(string CategoryIDlist)
        {
            return this.dal.DeleteList(CategoryIDlist);
        }

        public bool Exists(int CategoryID)
        {
            return this.dal.Exists(CategoryID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public Chain.Model.TimingCategory GetModel(int CategoryID)
        {
            return this.dal.GetModel(CategoryID);
        }

        public List<Chain.Model.TimingCategory> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataSet GetNifo(string strWhere)
        {
            return this.dal.GetNifo(strWhere);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.TimingCategory model)
        {
            return this.dal.Update(model);
        }
    }
}

